<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body th:fragment="tooth_function">
<div class="wonderful-top">

    <div class="top-list top-list-one">
        <div onclick="mytext('zx')">
            <a class="write-artical" href="javascript:;" target="_self">
                <img src="/icon/icon_Questions.png" alt="有贝口腔网">
                <span>写文章</span>
            </a>
        </div>
        <div onclick="mytext('wd')">
            <a href="javascript:;" target="_self" id="qa">
                <img src="/icon/icon_Articles.png" alt="有贝口腔网">
                <span>提问题</span>
            </a>
        </div>
    </div>
    <div class="top-list top-list-two">
        <div>
            <a href="javascript:;" target="_self" onclick="showPlanFun()">
                <img src="/icon/Dentist.png" alt="有贝口腔网">
                <span>网上看牙</span>
            </a>
        </div>
        <div>
            <a href="http://www.hasbei.com/about/link" target="_blank">
                <img src="/icon/Factory.png" alt="有贝口腔网">
                <span>厂家入驻</span>
            </a>
        </div>
        <div>
            <a href="http://www.hasbei.com/about/link" target="_blank">
                <img src="/icon/Hospital.png" alt="有贝口腔网">
                <span>诊所入驻</span>
            </a>
        </div>
    </div>
</div>


    <div th:replace="common/hasbei_text"></div>


<script th:inline="javascript">

    window.myauto = [[${auto}]];
</script>

<script>
    function mytext(v) {
        var auto=window.myauto;
        if(auto!=""){
            $("#form-title").text("");

            if(v=="zx"){
                $("#form-title").val("");
                $("#form-title").attr("placeholder","请输入文章标题（5-100个汉字）")
                editor.txt.html('<p id="myplaceholder" style="color: #999">请输入相关口腔文章、资讯内容</p>')
                //$("#myplaceholder").text("请输入相关口腔文章、资讯内容")
                layer.open({
                    title: "發表文章"
                    , content: $('#mytext')
                    , type: 1
                    , area: ["auto", "auto"]
                    , anim: 5
                    , btn: ['yes', 'no']
                    ,yes: function(index, layero){
                        var title=$("#form-title").val();
                        var content=editor.txt.text();


                        if(title.length <= 5 && title.length <=100){
                            layer.msg("文章标题（5-100个汉字）");
                            return false;
                        }
                        if(editor.txt.text().length <= 50){
                            layer.msg("文章内容至少输入50字数");
                            return false;
                        }

                        var data={};
                        data['a_title']=title;
                        data['a_content']=content;

                        $.ajax({
                            type: "POST",
                            url: basePath + "consult/add",
                            data: data,
                            success: function (data) {
                                if(data=='ok'){
                                    layer.msg("文章发表成功，待审核")

                                    setTimeout(function(){
                                        layer.closeAll(); //疯狂模式，关闭所有层
                                    },1500)

                                }else{
                                    layer.msg("服务器出现异常")
                                }


                            }
                        });



                    }
                    ,btn2: function(index, layero){

                    }
                });
            }
            if(v=="wd"){
                $("#form-title").val("");
                $("#form-title").attr("placeholder","请输入口腔问题（5-100个汉字）以?号结尾")
                editor.txt.html('<p id="myplaceholder" style="color: #999">【非必填】，描述该口腔问题背景，如什么情况下产生这个问题</p>')

                layer.open({
                    title: "發表口腔问题"
                    , content: $('#mytext')
                    , type: 1
                    , area: ["auto", "auto"]
                    , anim: 5
                    , btn: ['yes', 'no']
                    ,yes: function(index, layero){
                        var title=$("#form-title").val();
                        var content=editor.txt.text();

                        if(title.length <= 5 && content.length <=100 && (content.indexOf('?')==-1)){
                            layer.msg("提问的字数必须是5个字以上？结尾");
                            return false;
                        }

                        var data={};
                        data['q_title']=title;
                        data['q_content']=content;

                        $.ajax({
                            type: "POST",
                            url: basePath + "answers/add",
                            data: data,
                            success: function (data) {
                                if(data=='增加成功'){
                                    layer.msg("问题发表成功，待审核")

                                    setTimeout(function(){
                                        layer.closeAll(); //疯狂模式，关闭所有层
                                    },1500)

                                }else{
                                    layer.msg("服务器出现异常")
                                }
                            }
                        });
                    }
                    ,btn2: function(index, layero){
                        //按钮【按钮二】的回调
                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });
            }
        }else{
            window.location.href="/login";
        }
    }
</script>

</body>
</html>